/**
 * Copyright 2010 Adam Ruggles.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.code.sapien.model;

import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

/**
 * Setting entity data model.  Used for storing Sapien settings.
 * @author Adam
 * @version $Id$
 * 
 * Created on Jan 4, 2010 at 7:22:27 PM 
 */
@javax.persistence.Entity @Table(name = "sapien_settings")
public class Setting implements Serializable {
	/**
	 * Serial Version UID.
	 */
	private static final long serialVersionUID = -4325281353007046300L;

	/**
	 * A description of the setting (optional).
	 */
	private String description;

	/**
	 * The setting name, must be unique.
	 */
	private String name;

	/**
	 * The value of the setting.
	 */
	private String value;

	/**
	 * {@inheritDoc}
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(final Object obj) {
		if (this == obj) {
			return true;
		}
		if (!(obj instanceof Setting)) {
			return false;
		}
		final Setting rhs = (Setting) obj;
		return new EqualsBuilder()
			.append(name, rhs.getName())
			.append(value, rhs.getValue())
			.isEquals();
	}

	/**
	 * Returns description.
	 * @return the description.
	 */
	@Basic
	public String getDescription() {
		return description;
	}

	/**
	 * Returns name.
	 * @return the name.
	 */
	@Id @Column(length = 20)
	public String getName() {
		return name;
	}

	/**
	 * Returns value.
	 * @return the value.
	 */
	@Basic
	public String getValue() {
		return value;
	}

	/**
	 * {@inheritDoc}
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return new HashCodeBuilder(19, 37)
			.append(name)
			.append(value)
			.toHashCode();
	}

	/**
	 * Sets description.
	 * @param description the description to set.
	 */
	public void setDescription(final String description) {
		this.description = description;
	}

	/**
	 * Sets name.
	 * @param name the name to set.
	 */
	public void setName(final String name) {
		this.name = name;
	}

	/**
	 * Sets value.
	 * @param value the value to set.
	 */
	public void setValue(final String value) {
		this.value = value;
	}

	/**
	 * {@inheritDoc}
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return new ToStringBuilder(this)
			.append("name", name)
			.append("description", description)
			.append("value", value)
			.toString();
	}
}
